package cn.com.wdjedu.androidapp.wjeduandroid.ui.introduceui;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.wdjedu.androidapp.wjeduandroid.R;
import cn.com.wdjedu.androidapp.wjeduandroid.mvp.MvpActivity;
import cn.com.wdjedu.androidapp.wjeduandroid.mvp.introduce.introduceBean;
import cn.com.wdjedu.androidapp.wjeduandroid.mvp.introduce.introducePresenter;
import cn.com.wdjedu.androidapp.wjeduandroid.mvp.introduce.introduceview;
import cn.com.wdjedu.androidapp.wjeduandroid.support.lib.global.GlobalContext;
import cn.com.wdjedu.androidapp.wjeduandroid.ui.mainfragment.MainBean;

/**
 * 课程单元展示
 */

@SuppressWarnings("FieldCanBeLocal")
public class CourseIntroduceActivity extends MvpActivity<introducePresenter> implements introduceview {
    //常量当前时间
    //public static final String CURRENT_TIME="current_time";

    //导航栏对象
    //TabPageIndicator mIndicator;
    //ViewPager承载
    //DecoratorViewPager mViewPager;

    //@BindView(R.id.view_super_player)
    //SuperPlayer mViewSuperPlayer;

    @BindView(R.id.course_name)
    TextView mTvSuperPlayerComplete;
    @BindView(R.id.listView)
    GridView listView;
    List<MainBean.CourseBean.ContentBean> lists = new ArrayList<>();
    @BindView(R.id.goback)
    ImageView goback;
    private VideoGridViewAdapter adtper;
    //记录当前播放的时长
    //private int currentTime;
    //播放器播放的url
    //private String url;
    //是否橫屏
    //private boolean isLand;
    //接收课程typeId
    private int typeId;

    public static Intent newIntent() {
        Intent intent = new Intent(GlobalContext.getInstance().getApplicationContext(), CourseIntroduceActivity.class);
        Bundle bundle = new Bundle();
        intent.putExtras(bundle);
        return intent;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
//<<<<<<< HEAD
//        requestWindowFeature(Window.FEATURE_NO_TITLE);
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//        super.onCreate(savedInstanceState);
//
//=======
        super.onCreate(savedInstanceState);
        // requestWindowFeature(Window.FEATURE_NO_TITLE);
        //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//>>>>>>> 058627a5335f955004c01a2b8af7ad08ae924e68
        setContentView(R.layout.gridview_layout);
        updateTitle("东方标准X");
        ButterKnife.bind(this);
        initView();
        // initData(savedInstanceState);
        // initTagAdapter();

    }

    @Override
    protected introducePresenter createPresenter() {
        return new introducePresenter(this);
    }

//    private void initData(Bundle savedInstanceState) {
//        if (savedInstanceState != null) {
//            //   currentTime=savedInstanceState.getInt(CURRENT_TIME);
//        }
//    }

    /**
     * 初始化导航栏
     */
//    private void initTagAdapter() {
//        if (!isLand){
//            BasePagerAdapter adapter = new BasePagerAdapter(getSupportFragmentManager());
//            mViewPager.setAdapter(adapter);
//            mIndicator.setViewPager(mViewPager);
//            setTabPagerIndicator();
//        }
//       // playVideo(); /*视屏播放*/
//    }
    private void initView() {
        // Log.d("Raj", "initView: 666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666");

        Bundle bundle = this.getIntent().getExtras();
        mTvSuperPlayerComplete.setText(bundle.getString("CourseName"));
        mvpPresenter.queryIntroduceData(bundle.getInt("CourseType"));

        adtper = new VideoGridViewAdapter(this, R.layout.activity_index_gallery_item, lists);
        listView.setAdapter(adtper);

        goback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }


    /**
     * 下面的这几个Activity的生命状态很重要
     */
    @Override
    public void onPause() {
        super.onPause();
//        if (mViewSuperPlayer != null) {
//            currentTime=mViewSuperPlayer.getCurrentPosition();
//            mViewSuperPlayer.onPause();
//        }
    }

    @Override
    public void onResume() {
        super.onResume();
//        if (mViewSuperPlayer != null) {
//            mViewSuperPlayer.onResume();
//        }
    }

    @Override
    public void onDestroy() {

//        if (mViewSuperPlayer != null) { /*播放器释放*/
//            mViewSuperPlayer.onDestroy();
//        }

        super.onDestroy();
    }


    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
//        if (mViewSuperPlayer != null) {
//            mViewSuperPlayer.onConfigurationChanged(newConfig);
//        }
    }

    @Override
    public void queryNewIntroduceData(introduceBean introBean) {
        lists.clear();
        lists.addAll(introBean.getLists());
        adtper.notifyDataSetChanged();
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showError(String error) {

    }


    /**
     * 判断当前设备是手机还是平板，代码来自 Google I/O App for Android
     *
     * @param context
     * @return 平板返回 True，手机返回 False
     */
    public static boolean isPad(Context context) {
        return (context.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK)
                >= Configuration.SCREENLAYOUT_SIZE_LARGE;
    }

    /**
     * 设置导航栏的参数类型
     */
//    private void setTabPagerIndicator() {
//        mIndicator.setIndicatorMode(TabPageIndicator.IndicatorMode.MODE_NOWEIGHT_EXPAND_NOSAME);// 设置模式，一定要先设置模式
//        mIndicator.setDividerColor(Color.parseColor("#00bbcf"));// 设置分割线的颜色
//        mIndicator.setDividerPadding(CommonUtils.dip2px(GlobalContext.getInstance(), 10));
//        mIndicator.setIndicatorColor(Color.parseColor("#43A44b"));// 设置底部导航线的颜色
//        mIndicator.setTextColorSelected(Color.parseColor("#43A44b"));// 设置tab标题选中的颜色
//        mIndicator.setTextColor(Color.parseColor("#797979"));// 设置tab标题未被选中的颜色
//        mIndicator.setTextSize(CommonUtils.sp2px(GlobalContext.getInstance(), 20));// 设置字体大小
//    }


    /**
     * 底部展示的三个模块的Fragmnet适配器
     */
//    class BasePagerAdapter extends FragmentPagerAdapter {
//        String[] titles;
//
//        public BasePagerAdapter(FragmentManager fm) {
//            super(fm);
//            this.titles = CommonUtils.getStringArray(R.array.expand_courses);
//        }
//
//        @Override
//        public Fragment getItem(int position) {
//            return CourseFragmentFactory.createForNoExpand(position);
//        }
//
//        @Override
//        public int getCount() {
//            return titles.length;
//        }
//
//        @Override
//        public CharSequence getPageTitle(int position) {
//            return titles[position];
//        }
//    }


//    @Override
//    public void onBackPressed() {
////        if (mViewSuperPlayer != null && mViewSuperPlayer.onBackPressed()) {
////            return;
////        }
//        super.onBackPressed();
//    }


}
